package com.onlyphoto.onlymall.mvp.presenter

import android.content.Context
import com.onlyphoto.onlymall.base.BaseEntity
import com.onlyphoto.onlymall.base.BaseNetworkResponse
import com.onlyphoto.onlymall.base.BaseObserver

import com.onlyphoto.onlymall.mvp.contract.COrderDetails
import com.onlyphoto.onlymall.mvp.model.MOrderDetailsImpl
import com.onlyphoto.onlymall.base.BasePresenter
import com.onlyphoto.onlymall.bean.request.ConfirmReceiveBean
import com.onlyphoto.onlymall.bean.response.OrderDetailsBean


class POrderDetailsImpl(mContext: Context, mView: COrderDetails.IVOrderDetails) : BasePresenter<COrderDetails.IVOrderDetails, MOrderDetailsImpl>(mContext, mView, MOrderDetailsImpl()), COrderDetails.IPOrderDetails {
    override fun getOrderDetails(getType: Int, orderId: Int) {
        mModel.requestOrderDetails(getType, orderId, object :BaseObserver<OrderDetailsBean>(mContext.get()){
            override fun onSuccess(data: OrderDetailsBean?, msg: String?) {
                mView.getOrderDetailsSuccess(data!!)
            }

            override fun onCodeError(t: BaseNetworkResponse<OrderDetailsBean>?) {
            }

            override fun onFailure(e: Throwable?) {
            }

            override fun onRequestStart() {
            }

            override fun onFinally() {
            }

        })
    }

    override fun confirmReceive() {
        val bean = mView.setConfirmReceiveBean()
        mModel.confirmReceice(bean, object :BaseObserver<BaseEntity>(mContext.get()){
            override fun onSuccess(data: BaseEntity?, msg: String?) {
                mView.confirmReceiveSuccess()
            }

            override fun onCodeError(t: BaseNetworkResponse<BaseEntity>?) {
            }

            override fun onFailure(e: Throwable?) {
            }

            override fun onRequestStart() {
            }

            override fun onFinally() {
            }

        })
    }

    override fun getUploadedPic(orderId: String, goodsId: String) {
        mModel.getUploadedPic(orderId, goodsId, object :BaseObserver<ArrayList<String>>(mContext.get()){
            override fun onSuccess(data: ArrayList<String>?, msg: String?) {
                if (data == null) {
                    mView.noUploadedPic()
                }
                mView.getUploadedPicSuccess(data!!)
            }

            override fun onCodeError(t: BaseNetworkResponse<ArrayList<String>>?) {
            }

            override fun onFailure(e: Throwable?) {
            }

            override fun onRequestStart() {
            }

            override fun onFinally() {
            }

        })
    }
}
